# -*- coding: utf-8 -*-
import urllib,urllib2, cookielib,re,json
# 登录过的有效cookie
fake_cookie='ASP.NET_SessionId=rd3a02zk3121qn55u5dof545; cnzz_a2707565=0; sin2707565=http%3A//localhost/baoguan/index.asp; rtime=0; ltime=1301497028750; cnzz_eid=89619595-1301493197-http%3A//localhost/baoguan/index.asp'

cookie_support= urllib2.HTTPCookieProcessor(cookielib.CookieJar())
opener = urllib2.build_opener(cookie_support, urllib2.HTTPHandler)
urllib2.install_opener(opener)
# 登录信息
login_post_data=urllib.urlencode({
	'page':'1',
	'rows':'100'
})
headers = {
	'Cookie':fake_cookie
}
# 返回的车辆信息，是json格式，可以用get方式，也可以用post方式获取
json_VehicleInfo = urllib2.Request(
	
	url = 'http://www.zjetc.net/Accounts/VehicleInfoPage?page=1&rows=100',
	data = login_post_data,
	headers = headers
)

# 返回的是客户的基本信息，html直接返回
# http://www.zjetc.net/Accounts/CustomerInfo

# 返回待查询的车辆列表，json格式，不带参数查询，里面信息很丰富，可以好好研究
# http://www.zjetc.net/Accounts/LoadVehicle

# 返回查询值，json格式，如果没查询到，也会返回1条数据，内容都为null，三个参数，参数格式如下：
# beginDate:2011-03-01
# endDate:2011-03-29
# vehicle:浙B8E790
# http://www.zjetc.net/Accounts/DetailPage


login_result = urllib2.urlopen(json_VehicleInfo).read()
# 获取cookies
cookies = filter(lambda h:isinstance(h, urllib2.HTTPCookieProcessor), opener.handlers)[0].cookiejar
print cookies
if(login_result.headers.has_key('Cookie')):
	c=login_result.headers.get('Cookie')
	print c
# print login_result
j=json.loads(login_result)
print j["total"]
for x in j["rows"]:
	print x["VC_VEHICLE_CODE"]
 
	# for r in x["rows"]:
		# print r["VC_VEHICLE_CODE"]
# values = {’redirect’:”, ‘email’:'abc@abc.com’, ‘password’:'password’, ‘rememberme’:”, ’submit’:'OK, Let Me In!’}
# data = urllib.urlencode(values)
# request = urllib2.Request(url, data)
# url = urlOpener.open(request)
# print url.info()
# page = url.read()
# request = urllib2.Request(url)
# url = urlOpener.open(request)
# page = url.read()
# print page

# Cookie:ASP.NET_SessionId=5murrt55vt22ay55k2awp055